package com.nongtai.result;

import com.nongtai.enums.ReturnCodeEnum;
import lombok.Data;
import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private String code;   //编码
    private String msg;   //错误信息
    private T data;   // 数据
    private long time;   // 时间

    public Result(){
        this.time = System.currentTimeMillis()/1000;
    }

    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.setCode(ReturnCodeEnum.RC200.getCode());
        result.setMsg(ReturnCodeEnum.RC200.getMessage());
        return result;
    }

    public static <T> Result<T> success(T object){
        Result<T> result = new Result<>();
        result.setCode(ReturnCodeEnum.RC200.getCode());
        result.setMsg(ReturnCodeEnum.RC200.getMessage());
        result.setData(object);
        return result;
    }

    public static <T> Result<T> error(String msg,String code){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
